# -*- coding: UTF-8 -*-
"""
    TweMoi, aplicación Android para la interacción con redes sociales
    Copyright (C) 2011
        * Autor: Moisés Vázquez Sánchez
        * Tutor: Jesús M. González Barahona
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

from google.appengine.ext import db

class Red(db.Model):
    author = db.UserProperty()
    user_twemoi = db.StringProperty()
    tipo_red = db.StringProperty()
    user_red = db.StringProperty()
    comment = db.StringProperty(multiline=True)
    date = db.DateTimeProperty(auto_now_add=True)

class Usuario(db.Model):
    author = db.UserProperty()
    user_twemoi = db.StringProperty(required=True)
    urlImage = db.StringProperty()
   
    def put (self): 
        # Comprobamos si no hay un usuario duplicado.
        if (not((not self.is_saved()) and (Amigo.gql ('WHERE user_twemoi = :1', self.user_twemoi).count() > 0))):
                db.Model.put (self)

class Amigo(db.Model):
    author = db.UserProperty()
    user_twemoi = db.StringProperty()
    nombre_amigo = db.StringProperty()
    id_user_red = db.StringProperty()
    red = db.StringProperty()
    urlImage = db.StringProperty()
    
    def put (self):
        # Comprobamos si no hay un usuario amigo duplicado.
        if (not((not self.is_saved()) and (Amigo.gql ('WHERE nombre_amigo = :1 AND user_twemoi = :2', self.nombre_amigo, self.user_twemoi).count() > 0))):
            db.Model.put (self)
